﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Calibration.CApCalibrationSetsModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Calibration.Resources;
using EngineeringInternalExtension;
using Microsoft.CSharp.RuntimeBinder;
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.Calibration;

public class CApCalibrationSetsModel : INotifyPropertyChanged
{
  private TxColor ColorDevice = TxColor.TxColorGray;
  private TxColor ColorVirtual = TxColor.TxColorOrange;
  private TxColor ColorActual = TxColor.TxColorBlue;
  private TxColor ColorTargets = TxColor.TxColorMagenta;
  private ObservableCollection<CApCalibrationSet> _CalibrationSets;
  private CApCalibrationSet _SelectedCalibrationSet;
  private bool _IsEmphasized;
  private int _AppliedOrderCounter = 1;

  public event PropertyChangedEventHandler PropertyChanged;

  public ObservableCollection<CApCalibrationSet> CalibrationSets
  {
    get => this._CalibrationSets;
    set => this._CalibrationSets = value;
  }

  public CApCalibrationSet SelectedCalibrationSet
  {
    get => this._SelectedCalibrationSet;
    set
    {
      if (this.IsEmphasized && this._SelectedCalibrationSet != null)
        this.StopEmphasizeSet(this._SelectedCalibrationSet);
      this._SelectedCalibrationSet = value;
      if (this.IsEmphasized && this._SelectedCalibrationSet != null)
      {
        this.EmphasizeSet(this._SelectedCalibrationSet);
        TxApplication.RefreshDisplay();
      }
      if (this.PropertyChanged == null)
        return;
      this.PropertyChanged((object) this, new PropertyChangedEventArgs(nameof (SelectedCalibrationSet)));
    }
  }

  public bool IsEmphasized
  {
    get => this._IsEmphasized;
    set
    {
      this._IsEmphasized = value;
      TxTypeFilter txTypeFilter = new TxTypeFilter();
      txTypeFilter.AddIncludedType(typeof (ITxDisplayableObject));
      TxObjectList allDescendants = TxApplication.ActiveDocument.PhysicalRoot.GetAllDescendants((ITxTypeFilter) txTypeFilter);
      TxColor txColorWhite = TxColor.TxColorWhite;
      txColorWhite.Transparency = 0.5;
      if (this._IsEmphasized)
      {
        foreach (ITxDisplayableObject displayableObject in (Collection<ITxObject>) allDescendants)
          TxDisplayableObjectEx.EmphasizeObject(displayableObject, txColorWhite, (TxColorEmphasizePriority) 200);
        if (this.SelectedCalibrationSet != null)
          this.EmphasizeSet(this.SelectedCalibrationSet);
      }
      else
      {
        foreach (ITxDisplayableObject displayableObject in (Collection<ITxObject>) allDescendants)
          TxDisplayableObjectEx.StopEmphasizeObject(displayableObject, txColorWhite, (TxColorEmphasizePriority) 200);
        if (this._SelectedCalibrationSet != null)
          this.StopEmphasizeSet(this._SelectedCalibrationSet);
      }
      TxApplication.RefreshDisplay();
      if (this.PropertyChanged == null)
        return;
      this.PropertyChanged((object) this, new PropertyChangedEventArgs(nameof (IsEmphasized)));
    }
  }

  public int AppliedOrderCounter
  {
    get => this._AppliedOrderCounter;
    set => this._AppliedOrderCounter = value;
  }

  public void ApplySet(CApCalibrationSet cs)
  {
    if (!cs.Apply(this.AppliedOrderCounter))
      return;
    ++this.AppliedOrderCounter;
    TxApplication.RefreshDisplay();
  }

  public void UnapplySet(CApCalibrationSet cs)
  {
    if (!cs.IsApplied)
      return;
    int appliedOrder = cs.AppliedOrder;
    if (!cs.Unapply())
      return;
    this.FixAppliedOrder(appliedOrder);
    TxApplication.RefreshDisplay();
  }

  public void DeleteSet(CApCalibrationSet cs)
  {
    if (this.CalibrationSets.Count > 1)
    {
      int num = this.CalibrationSets.IndexOf(cs);
      int index = num + 1;
      if (index == this.CalibrationSets.Count)
        index = num - 1;
      this.SelectedCalibrationSet = this.CalibrationSets[index];
    }
    int appliedOrder = cs.AppliedOrder;
    this.CalibrationSets.Remove(cs);
    if (!cs.IsApplied)
      return;
    this.FixAppliedOrder(appliedOrder);
  }

  private void EmphasizeSet(CApCalibrationSet cs)
  {
    TxDisplayableObjectEx.EmphasizeObject((ITxDisplayableObject) cs.Device, this.ColorDevice, (TxColorEmphasizePriority) 200);
    foreach (ITxDisplayableObject targetObject in (Collection<ITxObject>) cs.TargetObjectList)
      TxDisplayableObjectEx.EmphasizeObject(targetObject, this.ColorTargets, (TxColorEmphasizePriority) 200);
    foreach (CApCalibrationPair calibrationPair in (Collection<CApCalibrationPair>) cs.CalibrationTransform.CalibrationPairs)
      this.EmphasizeCalibrationPair(calibrationPair, true);
  }

  private void StopEmphasizeSet(CApCalibrationSet cs)
  {
    TxDisplayableObjectEx.StopEmphasizeObject((ITxDisplayableObject) cs.Device, this.ColorDevice, (TxColorEmphasizePriority) 200);
    foreach (ITxDisplayableObject targetObject in (Collection<ITxObject>) cs.TargetObjectList)
      TxDisplayableObjectEx.StopEmphasizeObject(targetObject, this.ColorTargets, (TxColorEmphasizePriority) 200);
    foreach (CApCalibrationPair calibrationPair in (Collection<CApCalibrationPair>) cs.CalibrationTransform.CalibrationPairs)
      this.EmphasizeCalibrationPair(calibrationPair, false);
  }

  public void AddTargetObjectToSet(CApCalibrationSet cs, ITxObject targetObject)
  {
    if (this.IsEmphasized)
    {
      TxDisplayableObjectEx.EmphasizeObject((ITxDisplayableObject) targetObject, this.ColorTargets, (TxColorEmphasizePriority) 200);
      TxApplication.RefreshDisplay();
    }
    cs.AddTargetObject(targetObject);
  }

  public void AddCalibrationPairToSet(CApCalibrationSet cs, CApCalibrationPair cp)
  {
    if (this.IsEmphasized)
    {
      this.EmphasizeCalibrationPair(cp, true);
      TxApplication.RefreshDisplay();
    }
    cp.ActualLocation = cp.ActualPoint.AbsoluteLocation;
    cp.VirtualLocation = cp.VirtualPoint.AbsoluteLocation;
    cs.AddCalibrationPair(cp);
  }

  public void RemoveTargetObjectFromSet(CApCalibrationSet cs, ITxObject targetObject)
  {
    if (this.IsEmphasized)
    {
      TxDisplayableObjectEx.StopEmphasizeObject((ITxDisplayableObject) targetObject, this.ColorTargets, (TxColorEmphasizePriority) 200);
      TxApplication.RefreshDisplay();
    }
    cs.RemoveTargetObject(targetObject);
  }

  public void RemoveCalibrationPairFromSet(CApCalibrationSet cs, CApCalibrationPair cp)
  {
    if (this.IsEmphasized)
    {
      this.EmphasizeCalibrationPair(cp, false);
      TxApplication.RefreshDisplay();
    }
    cs.RemoveCalibrationPair(cp);
  }

  public void EmphasizeCalibrationPair(CApCalibrationPair cp, bool emphasize)
  {
    if (emphasize)
    {
      TxDisplayableObjectEx.EmphasizeObject((ITxDisplayableObject) cp.ActualPoint, this.ColorActual, (TxColorEmphasizePriority) 200);
      TxDisplayableObjectEx.EmphasizeObject((ITxDisplayableObject) cp.VirtualPoint, this.ColorVirtual, (TxColorEmphasizePriority) 200);
    }
    else
    {
      TxDisplayableObjectEx.StopEmphasizeObject((ITxDisplayableObject) cp.ActualPoint, this.ColorActual, (TxColorEmphasizePriority) 200);
      TxDisplayableObjectEx.StopEmphasizeObject((ITxDisplayableObject) cp.VirtualPoint, this.ColorVirtual, (TxColorEmphasizePriority) 200);
    }
  }

  public void Clone(CApCalibrationSet target, CApCalibrationSet source)
  {
    if (this.IsEmphasized)
      this.StopEmphasizeSet(target);
    target.Clone(source);
    if (this.IsEmphasized)
      this.EmphasizeSet(target);
    TxApplication.RefreshDisplay();
  }

  public bool CheckUniqueName(string CalibrationSetName)
  {
    bool flag = true;
    foreach (CApCalibrationSet calibrationSet in (Collection<CApCalibrationSet>) this.CalibrationSets)
    {
      if (calibrationSet.Name.Equals(CalibrationSetName))
      {
        flag = false;
        break;
      }
    }
    return flag;
  }

  private void FixAppliedOrder(int removedOrder)
  {
    int num = 0;
    foreach (CApCalibrationSet calibrationSet in (Collection<CApCalibrationSet>) this.CalibrationSets)
    {
      if (calibrationSet.AppliedOrder > removedOrder)
        --calibrationSet.AppliedOrder;
      if (calibrationSet.AppliedOrder > num)
        num = calibrationSet.AppliedOrder;
    }
    this.AppliedOrderCounter = num + 1;
  }

  public bool ExportSet(CApCalibrationSet cs, string FilePath)
  {
    bool flag = true;
    object obj = (object) Missing.Value;
    CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
    // ISSUE: variable of a compiler-generated type
    Application instance = (Application) Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("00024500-0000-0000-C000-000000000046")));
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    // ISSUE: reference to a compiler-generated method
    // ISSUE: variable of a compiler-generated type
    _Workbook workbook = (_Workbook) instance.Workbooks.Add(obj);
    // ISSUE: reference to a compiler-generated field
    if (CApCalibrationSetsModel.\u003C\u003Eo__36.\u003C\u003Ep__0 == null)
    {
      // ISSUE: reference to a compiler-generated field
      CApCalibrationSetsModel.\u003C\u003Eo__36.\u003C\u003Ep__0 = CallSite<Func<CallSite, object, _Worksheet>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.ConvertExplicit, typeof (_Worksheet), typeof (CApCalibrationSetsModel)));
    }
    // ISSUE: reference to a compiler-generated field
    // ISSUE: reference to a compiler-generated field
    // ISSUE: variable of a compiler-generated type
    _Worksheet worksheet = CApCalibrationSetsModel.\u003C\u003Eo__36.\u003C\u003Ep__0.Target((CallSite) CApCalibrationSetsModel.\u003C\u003Eo__36.\u003C\u003Ep__0, workbook.ActiveSheet);
    worksheet.Name = CalibrationResources.CALIBRATION_NAME;
    int num1 = 1;
    // ISSUE: variable of a compiler-generated type
    Range cells1 = worksheet.Cells;
    int num2 = num1;
    int RowIndex1 = num2 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex2 = (ValueType) num2;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex1 = (ValueType) 1;
    string upper1 = CalibrationResources.CALIBRATION_CURRENT_INFO_HEADER.ToUpper();
    cells1[(object) RowIndex2, (object) ColumnIndex1] = (object) upper1;
    worksheet.Cells[(object) RowIndex1, (object) 1] = (object) CalibrationResources.CALIBRATION_CURRENT_INFO_NAME;
    // ISSUE: variable of a compiler-generated type
    Range cells2 = worksheet.Cells;
    int num3 = RowIndex1;
    int RowIndex3 = num3 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex4 = (ValueType) num3;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex2 = (ValueType) 2;
    string name = cs.Name;
    cells2[(object) RowIndex4, (object) ColumnIndex2] = (object) name;
    worksheet.Cells[(object) RowIndex3, (object) 1] = (object) CalibrationResources.CALIBRATION_CURRENT_INFO_ROBOT_DEVICE;
    // ISSUE: variable of a compiler-generated type
    Range cells3 = worksheet.Cells;
    int num4 = RowIndex3;
    int RowIndex5 = num4 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex6 = (ValueType) num4;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex3 = (ValueType) 2;
    string deviceName = cs.DeviceName;
    cells3[(object) RowIndex6, (object) ColumnIndex3] = (object) deviceName;
    worksheet.Cells[(object) RowIndex5, (object) 1] = (object) CalibrationResources.CALIBRATION_CURRENT_INFO_MAINTAIN_ORIENTATION;
    // ISSUE: variable of a compiler-generated type
    Range cells4 = worksheet.Cells;
    int num5 = RowIndex5;
    int RowIndex7 = num5 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex8 = (ValueType) num5;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex4 = (ValueType) 2;
    string str1 = cs.IsMaintainOrientation ? CalibrationResources.CALIBRATION_YES : CalibrationResources.CALIBRATION_NO;
    cells4[(object) RowIndex8, (object) ColumnIndex4] = (object) str1;
    worksheet.Cells[(object) RowIndex7, (object) 1] = (object) CalibrationResources.CALIBRATION_CURRENT_INFO_RELATIVE_FRAME;
    string str2;
    if (TxFrame.op_Equality(cs.RelativeToFrame, (ITxObject) null))
    {
      if (TxTransformation.op_Equality(cs.RelativeToTransformation, (TxTransformation) null) || TxTransformation.op_Equality(cs.RelativeToTransformation, TxApplication.ActiveDocument.WorkingFrame))
      {
        str2 = CalibrationResources.CALIBRATION_WORKING_FRAME;
      }
      else
      {
        string[] strArray = new string[14];
        strArray[0] = CalibrationResources.CALIBRATION_PICKED_FRAME;
        strArray[1] = "(";
        strArray[2] = cs.RelativeToTransformation.Translation.X.ToString();
        strArray[3] = ",";
        double num6 = cs.RelativeToTransformation.Translation.Y;
        strArray[4] = num6.ToString();
        strArray[5] = ",";
        num6 = cs.RelativeToTransformation.Translation.X;
        strArray[6] = num6.ToString();
        strArray[7] = ",";
        num6 = cs.RelativeToTransformation.RotationRPY_XYZ.X;
        strArray[8] = num6.ToString();
        strArray[9] = ",";
        num6 = cs.RelativeToTransformation.RotationRPY_XYZ.Y;
        strArray[10] = num6.ToString();
        strArray[11] = ",";
        num6 = cs.RelativeToTransformation.RotationRPY_XYZ.Z;
        strArray[12] = num6.ToString();
        strArray[13] = ")";
        str2 = string.Concat(strArray);
      }
    }
    else
      str2 = cs.RelativeToFrame.Name;
    // ISSUE: variable of a compiler-generated type
    Range cells5 = worksheet.Cells;
    int num7 = RowIndex7;
    int RowIndex9 = num7 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex10 = (ValueType) num7;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex5 = (ValueType) 2;
    string str3 = str2;
    cells5[(object) RowIndex10, (object) ColumnIndex5] = (object) str3;
    worksheet.Cells[(object) RowIndex9, (object) 1] = (object) CalibrationResources.CALIBRATION_SETS_GRID_DESCRIPTION_COL;
    // ISSUE: variable of a compiler-generated type
    Range cells6 = worksheet.Cells;
    int num8 = RowIndex9;
    int RowIndex11 = num8 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex12 = (ValueType) num8;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex6 = (ValueType) 2;
    string description = cs.Description;
    cells6[(object) RowIndex12, (object) ColumnIndex6] = (object) description;
    worksheet.Cells[(object) RowIndex11, (object) 1] = (object) CalibrationResources.CALIBRATION_SETS_GRID_LAST_MODIFIED_COL;
    // ISSUE: variable of a compiler-generated type
    Range cells7 = worksheet.Cells;
    int num9 = RowIndex11;
    int RowIndex13 = num9 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex14 = (ValueType) num9;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex7 = (ValueType) 2;
    string str4 = cs.LastModified.ToString($"{DateTimeFormatInfo.CurrentInfo.ShortDatePattern} {DateTimeFormatInfo.CurrentInfo.ShortTimePattern}");
    cells7[(object) RowIndex14, (object) ColumnIndex7] = (object) str4;
    worksheet.Cells[(object) RowIndex13, (object) 1] = (object) (CalibrationResources.CALIBRATION_EXPORTED + ":");
    // ISSUE: variable of a compiler-generated type
    Range cells8 = worksheet.Cells;
    int num10 = RowIndex13;
    int num11 = num10 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex15 = (ValueType) num10;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex8 = (ValueType) 2;
    string str5 = DateTime.Now.ToString($"{DateTimeFormatInfo.CurrentInfo.ShortDatePattern} {DateTimeFormatInfo.CurrentInfo.ShortTimePattern}");
    cells8[(object) RowIndex15, (object) ColumnIndex8] = (object) str5;
    int num12 = num11 + 1;
    // ISSUE: variable of a compiler-generated type
    Range cells9 = worksheet.Cells;
    int num13 = num12;
    int RowIndex16 = num13 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex17 = (ValueType) num13;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex9 = (ValueType) 1;
    string upper2 = CalibrationResources.CALIBRATION_CURRENT_PAIRS_HEADER.ToUpper();
    cells9[(object) RowIndex17, (object) ColumnIndex9] = (object) upper2;
    worksheet.Cells[(object) RowIndex16, (object) 2] = (object) CalibrationResources.CALIBRATION_CURRENT_PAIRS_VIRTUAL_COL;
    worksheet.Cells[(object) RowIndex16, (object) 6] = (object) CalibrationResources.CALIBRATION_CURRENT_PAIRS_ACTUAL_COL;
    // ISSUE: variable of a compiler-generated type
    Range cells10 = worksheet.Cells;
    int num14 = RowIndex16;
    int RowIndex18 = num14 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex19 = (ValueType) num14;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex10 = (ValueType) 10;
    string pairsDistanceCol = CalibrationResources.CALIBRATION_CURRENT_PAIRS_DISTANCE_COL;
    cells10[(object) RowIndex19, (object) ColumnIndex10] = (object) pairsDistanceCol;
    worksheet.Cells[(object) RowIndex18, (object) 1] = (object) CalibrationResources.CALIBRATION_CURRENT_PAIRS_ACTIVE_COL;
    worksheet.Cells[(object) RowIndex18, (object) 2] = (object) CalibrationResources.CALIBRATION_CURRENT_PAIRS_SOURCE_NAME_COL;
    worksheet.Cells[(object) RowIndex18, (object) 3] = (object) "X";
    worksheet.Cells[(object) RowIndex18, (object) 4] = (object) "Y";
    worksheet.Cells[(object) RowIndex18, (object) 5] = (object) "Z";
    worksheet.Cells[(object) RowIndex18, (object) 6] = (object) CalibrationResources.CALIBRATION_CURRENT_PAIRS_DESTINATION_NAME_COL;
    worksheet.Cells[(object) RowIndex18, (object) 7] = (object) "X";
    worksheet.Cells[(object) RowIndex18, (object) 8] = (object) "Y";
    worksheet.Cells[(object) RowIndex18, (object) 9] = (object) "Z";
    worksheet.Cells[(object) RowIndex18, (object) 10] = (object) CalibrationResources.CALIBRATION_CURRENT_PAIRS_BEFORE_COL;
    // ISSUE: variable of a compiler-generated type
    Range cells11 = worksheet.Cells;
    int num15 = RowIndex18;
    int RowIndex20 = num15 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex21 = (ValueType) num15;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex11 = (ValueType) 11;
    string currentPairsAfterCol = CalibrationResources.CALIBRATION_CURRENT_PAIRS_AFTER_COL;
    cells11[(object) RowIndex21, (object) ColumnIndex11] = (object) currentPairsAfterCol;
    if (cs.CalibrationTransform.CalibrationPairs == null || cs.CalibrationTransform.CalibrationPairs.Count == 0)
    {
      worksheet.Cells[(object) RowIndex20++, (object) 1] = (object) CalibrationResources.CALIBRATION_NOT_AVAILABLE;
    }
    else
    {
      foreach (CApCalibrationPair calibrationPair in (Collection<CApCalibrationPair>) cs.CalibrationTransform.CalibrationPairs)
      {
        worksheet.Cells[(object) RowIndex20, (object) 1] = (object) calibrationPair.IsActive;
        worksheet.Cells[(object) RowIndex20, (object) 2] = (object) ((ITxObject) calibrationPair.VirtualPoint).Name;
        worksheet.Cells[(object) RowIndex20, (object) 3] = (object) (calibrationPair.VirtualRelativeLocation.Translation.X / TxApplication.Options.Units.LinearMultiplier);
        worksheet.Cells[(object) RowIndex20, (object) 4] = (object) (calibrationPair.VirtualRelativeLocation.Translation.Y / TxApplication.Options.Units.LinearMultiplier);
        worksheet.Cells[(object) RowIndex20, (object) 5] = (object) (calibrationPair.VirtualRelativeLocation.Translation.Z / TxApplication.Options.Units.LinearMultiplier);
        worksheet.Cells[(object) RowIndex20, (object) 6] = (object) ((ITxObject) calibrationPair.ActualPoint).Name;
        worksheet.Cells[(object) RowIndex20, (object) 7] = (object) (calibrationPair.ActualRelativeLocation.Translation.X / TxApplication.Options.Units.LinearMultiplier);
        worksheet.Cells[(object) RowIndex20, (object) 8] = (object) (calibrationPair.ActualRelativeLocation.Translation.Y / TxApplication.Options.Units.LinearMultiplier);
        worksheet.Cells[(object) RowIndex20, (object) 9] = (object) (calibrationPair.ActualRelativeLocation.Translation.Z / TxApplication.Options.Units.LinearMultiplier);
        worksheet.Cells[(object) RowIndex20, (object) 10] = (object) (calibrationPair.DistanceBefore / TxApplication.Options.Units.LinearMultiplier);
        worksheet.Cells[(object) RowIndex20++, (object) 11] = (object) (calibrationPair.DistanceAfter / TxApplication.Options.Units.LinearMultiplier);
      }
    }
    int num16 = RowIndex20 + 1;
    // ISSUE: variable of a compiler-generated type
    Range cells12 = worksheet.Cells;
    int num17 = num16;
    int RowIndex22 = num17 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex23 = (ValueType) num17;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex12 = (ValueType) 1;
    string upper3 = CalibrationResources.CALIBRATION_CURRENT_RESULTS_HEADER.ToUpper();
    cells12[(object) RowIndex23, (object) ColumnIndex12] = (object) upper3;
    worksheet.Cells[(object) RowIndex22, (object) 1] = (object) "dX:";
    worksheet.Cells[(object) RowIndex22, (object) 2] = (object) (cs.CalibrationTransform.MaintainTransformation.Translation.X / TxApplication.Options.Units.LinearMultiplier);
    worksheet.Cells[(object) RowIndex22, (object) 3] = (object) "Rx:";
    worksheet.Cells[(object) RowIndex22, (object) 4] = (object) (cs.CalibrationTransform.MaintainTransformation.RotationRPY_XYZ.X / TxApplication.Options.Units.AngularMultiplier);
    worksheet.Cells[(object) RowIndex22, (object) 5] = (object) CalibrationResources.CALIBRATION_CURRENT_RESULTS_MAX_DIST;
    // ISSUE: variable of a compiler-generated type
    Range cells13 = worksheet.Cells;
    int num18 = RowIndex22;
    int RowIndex24 = num18 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex25 = (ValueType) num18;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex13 = (ValueType) 6;
    // ISSUE: variable of a boxed type
    __Boxed<double> local1 = (ValueType) (cs.CalibrationTransform.MaximumDistance / TxApplication.Options.Units.LinearMultiplier);
    cells13[(object) RowIndex25, (object) ColumnIndex13] = (object) local1;
    worksheet.Cells[(object) RowIndex24, (object) 1] = (object) "dY:";
    worksheet.Cells[(object) RowIndex24, (object) 2] = (object) (cs.CalibrationTransform.MaintainTransformation.Translation.Y / TxApplication.Options.Units.LinearMultiplier);
    worksheet.Cells[(object) RowIndex24, (object) 3] = (object) "Ry:";
    worksheet.Cells[(object) RowIndex24, (object) 4] = (object) (cs.CalibrationTransform.MaintainTransformation.RotationRPY_XYZ.Y / TxApplication.Options.Units.AngularMultiplier);
    worksheet.Cells[(object) RowIndex24, (object) 5] = (object) CalibrationResources.CALIBRATION_CURRENT_RESULTS_AVG_DIST;
    // ISSUE: variable of a compiler-generated type
    Range cells14 = worksheet.Cells;
    int num19 = RowIndex24;
    int RowIndex26 = num19 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex27 = (ValueType) num19;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex14 = (ValueType) 6;
    // ISSUE: variable of a boxed type
    __Boxed<double> local2 = (ValueType) (cs.CalibrationTransform.AverageDistance / TxApplication.Options.Units.LinearMultiplier);
    cells14[(object) RowIndex27, (object) ColumnIndex14] = (object) local2;
    worksheet.Cells[(object) RowIndex26, (object) 1] = (object) "dZ:";
    worksheet.Cells[(object) RowIndex26, (object) 2] = (object) (cs.CalibrationTransform.MaintainTransformation.Translation.Z / TxApplication.Options.Units.LinearMultiplier);
    worksheet.Cells[(object) RowIndex26, (object) 3] = (object) "Rz:";
    worksheet.Cells[(object) RowIndex26, (object) 4] = (object) (cs.CalibrationTransform.MaintainTransformation.RotationRPY_XYZ.Z / TxApplication.Options.Units.AngularMultiplier);
    worksheet.Cells[(object) RowIndex26, (object) 5] = (object) CalibrationResources.CALIBRATION_CURRENT_RESULTS_RMS;
    // ISSUE: variable of a compiler-generated type
    Range cells15 = worksheet.Cells;
    int num20 = RowIndex26;
    int num21 = num20 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex28 = (ValueType) num20;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex15 = (ValueType) 6;
    // ISSUE: variable of a boxed type
    __Boxed<double> local3 = (ValueType) (cs.CalibrationTransform.RootMeanSquare / TxApplication.Options.Units.LinearMultiplier);
    cells15[(object) RowIndex28, (object) ColumnIndex15] = (object) local3;
    int num22 = num21 + 1;
    // ISSUE: variable of a compiler-generated type
    Range cells16 = worksheet.Cells;
    int num23 = num22;
    int num24 = num23 + 1;
    // ISSUE: variable of a boxed type
    __Boxed<int> RowIndex29 = (ValueType) num23;
    // ISSUE: variable of a boxed type
    __Boxed<int> ColumnIndex16 = (ValueType) 1;
    string str6 = CalibrationResources.CALIBRATION_CURRENT_TARGET_OBJECTS_HEADER + ":";
    cells16[(object) RowIndex29, (object) ColumnIndex16] = (object) str6;
    if (cs.TargetObjectList == null || ((Collection<ITxObject>) cs.TargetObjectList).Count == 0)
    {
      // ISSUE: variable of a compiler-generated type
      Range cells17 = worksheet.Cells;
      int num25 = num24;
      int num26 = num25 + 1;
      // ISSUE: variable of a boxed type
      __Boxed<int> RowIndex30 = (ValueType) num25;
      // ISSUE: variable of a boxed type
      __Boxed<int> ColumnIndex17 = (ValueType) 1;
      string calibrationNotAvailable = CalibrationResources.CALIBRATION_NOT_AVAILABLE;
      cells17[(object) RowIndex30, (object) ColumnIndex17] = (object) calibrationNotAvailable;
    }
    else
    {
      foreach (ITxObject targetObject in (Collection<ITxObject>) cs.TargetObjectList)
        worksheet.Cells[(object) num24++, (object) 1] = (object) targetObject.Name;
    }
    try
    {
      if (File.Exists(FilePath))
        File.Delete(FilePath);
      // ISSUE: reference to a compiler-generated method
      workbook.SaveAs((object) FilePath, (object) XlFileFormat.xlWorkbookNormal, obj, obj, obj, obj, XlSaveAsAccessMode.xlExclusive, obj, obj, obj, obj, obj);
    }
    catch (Exception ex)
    {
      flag = false;
    }
    // ISSUE: reference to a compiler-generated method
    workbook.Close((object) false, obj, obj);
    // ISSUE: reference to a compiler-generated method
    instance.Quit();
    return flag;
  }

  public bool LoadFromXml()
  {
    ObservableCollection<CApCalibrationSet> calibrationSets = new ObservableCollection<CApCalibrationSet>();
    bool flag = CApCalibrationSetsXmlManager.LoadCalibrationXml(ref calibrationSets);
    this.AppliedOrderCounter = 0;
    foreach (CApCalibrationSet capCalibrationSet in (Collection<CApCalibrationSet>) calibrationSets)
    {
      if (capCalibrationSet.AppliedOrder > this.AppliedOrderCounter)
        this.AppliedOrderCounter = capCalibrationSet.AppliedOrder;
      this.CalibrationSets.Add(capCalibrationSet);
    }
    ++this.AppliedOrderCounter;
    if (calibrationSets.Count != this.CalibrationSets.Count)
      flag = false;
    return flag;
  }

  public void StoreToXml() => CApCalibrationSetsXmlManager.SaveCalibrationXml(this.CalibrationSets);
}
